/**
 * <AiRmob-Framework; A simple augmented reality framework for android >
    Copyright (C) <2012>  <AiRmob Team>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package rendercomponents;

import android.opengl.GLES20;

public class Texture {

	public int ID;
	String resourcePath;
	
	/**
	 * Generates a texture for the image found under path.
	 * 
	 * @param r used Renderer
	 * @param path Path to the texture that shall be imported.
	 */
	public Texture(Renderer r, String path, ImageType type){
		this.resourcePath = path;
		if (type == ImageType.GIF || type == ImageType.JPG || type == ImageType.PNG || type == ImageType.UNKNOWN)
			this.ID = r.resourceManager.loadTextureFromFile(path, r.mContext, ID);
		else {
			System.out.println("Unsupported imagefile-type");
		}
		r.resourceManager.loadedTextures.add(this);
	}
	
	
	/**
	 * 
	 * Generates a new texture with the ID of an already existing texture.
	 * 
	 * @param textureID ID of the already existing texture to use for this new one.
	 */
	public Texture(int textureID){
		this.ID = textureID;
	}
	
	/**
	 * 
	 * Changes the filters for minification and magnification for this texture.
	 * 
	 * @param MinificationFilter  GLES20.GL_LINEAR or GLES20.GL_NEAREST
	 * @param MagnificationFilter  GLES20.GL_LINEAR or GLES20.GL_NEAREST
	 */
	public void setFilters(int MinificationFilter, int MagnificationFilter){
			GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, ID);

			GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
			GLES20.GL_TEXTURE_MIN_FILTER, MinificationFilter);
			GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
			GLES20.GL_TEXTURE_MAG_FILTER, MagnificationFilter);
			
			GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);		
	}
	
	/**
	 * 
	 * Changes the wrapping-behavior for this texture. 
	 * 
	 * @param sWrapping GLES20.GL_REPEAT,  GLES20.GL_CLAMP_TO_EDGE or GLES20.GL_MIRRORED_REPEAT
	 * @param tWrapping GLES20.GL_REPEAT,  GLES20.GL_CLAMP_TO_EDGE or GLES20.GL_MIRRORED_REPEAT
	 */
	public void setWrapping(int sWrapping, int tWrapping){
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, ID);
		
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
		GLES20.GL_TEXTURE_WRAP_S, sWrapping);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
		GLES20.GL_TEXTURE_WRAP_T, tWrapping);
		
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
	}

}
